package com.example.day05_umeng;

import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class RegisterActivity extends AppCompatActivity {

    private EditText mEtName;
    private EditText mEtPsd;
    private Button mBtnRegister;
    private String name;
    private String psd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        initViews();
    }

    private void initViews() {
        mEtName = findViewById(R.id.et_name);
        mEtPsd = findViewById(R.id.et_psd);
        mBtnRegister = findViewById(R.id.btn_register);
        mBtnRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                register();
            }
        });
    }

    private void register() {
        name = mEtName.getText().toString().trim();
        psd = mEtPsd.getText().toString().trim();
        if (TextUtils.isEmpty(name)&&TextUtils.isEmpty(psd)){
            Toast.makeText(this,"用户或密码不为空",Toast.LENGTH_LONG).show();
            return;
        }
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                   // EMClient.getInstance().createAccount(name, psd);//同步方法
                    showToast("注册成功");
                    finish();
                } catch (Exception e) {
                    e.printStackTrace();
                    showToast("注册失败");
                }
            }
        });

    }
    public void showToast(final String msg){
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Log.i("TAG", "run: "+msg);
            }
        });

    }
}
